<?php
namespace Admin\Model;
use Think\Model;
class DepotModel extends Model {
	public $page; //当前页
	public $perpage; //每页显示
	public $brand_id; //ID
	public $post; //提交的信息 数组
	public $table='zjy_depot';
	public $ids; //IDs 数组，用于删除

	//获取列表
	public function get_depot_list()
	{
		$page=$this->page;
		$perpage=$this->perpage;

		//搜索
		//$where='where a.member_state=1 and a.member_id=b.member_id ';
		if($this->keyword){
			$where.=" where `depot_name` LIKE '%".$this->keyword."%'";
		}

		$start=($page-1)*$perpage;
		$Model=new Model();


		$sql="SELECT depot_id,depot_name,depot_area_id,depot_sort FROM `zjy_depot`  ".$where."order by depot_sort asc,depot_id desc limit $start,$perpage";
		$list=$Model->query($sql);

		return $list;
	}

	public function get_depot_total()
	{
		$Model=M("depot");
		$count=$Model->count();
		return $count;
	}

	public function depot_add_post()
	{
		$data = $this->post;
		$Model = M("depot"); // 实例化对象

		if (!$this->depot_id) {
			$result = $Model->add($data);
		}else{
			$result = $Model->where('depot_id='.$this->depot_id)->save($data);
		}

		if($result === false) {
			return false;
		}else{
			return true;
		}
	}


	public function get_depot()
	{
		$depot_id=$this->$depot_id;
		$Model=M("depot"); // 实例化对象
		$list=$Model->field('depot_id,depot_name,depot_area_id,depot_sort')->where('depot_id='.$depot_id)->find();
		return $list;

	}


	public function update_depot_sort()
	{
		$ids=$this->ids;
		$sorts=$this->sorts;
		$Model=M("depot");
		foreach($ids as $k=>$v){
			$data['depot_sort']=$sorts[$k];
			$condition['depot_id']=$v;
			$result=$Model->where($condition)->save($data);
			if($result === false) {
				return false;
			}
		}
		return true;
	}

	public function delete_depot()
	{
		$ids=$this->ids;
		$Model=M("depot");

		foreach($ids as $v){
			$condition['depot_id']=$v;
			if(!$Model->where($condition)->delete()){
				return false;
			}
		}
		return true;
	}

}